<template>
    <div class="content_panel project_modules">
        <div class="content_panel_top">
            <h3 class="panel_title">
                <span>{{$t('finance.remitRecord')}}</span>
            </h3>
            <el-form ref="form" :model="form" :rules="rules" :inline="false" class="module_form">
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item prop="orderId" label="">
                            <el-input v-model="form.orderId" :placeholder="$t('common.innerOrderId')" clearable></el-input><!--内部订单号-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item prop="appName" label="">
                            <select-app-list v-model="form.appName" :placeholder="$t('system.appName')"></select-app-list><!--app名称-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item prop="userPhone" label="">
                            <el-input v-model="form.userPhone" :placeholder="$t('common.mobileNumber')" clearable></el-input><!--手机号码-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item prop="derateId" label="">
                            <el-input v-model="form.derateId" :placeholder="$t('common.remitApplyId')" clearable></el-input><!--减免申请编号-->
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item prop="userId" label="">
                            <el-input v-model="form.userId" clearable placeholder="UserId" maxlength="10"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item prop="derateApplyTime" label=""><!--申请时间-->
                            <el-date-picker
                                    style="width:100%"
                                    v-model="form.derateApplyTime"
                                    type="datetimerange"
                                    format="yyyy-MM-dd HH:mm:ss"
                                    value-format="timestamp"
                                    range-separator="-"
                                    :default-time="['00:00:00', '23:59:59']"
                                    :start-placeholder="$t('common.applyStartTime')"
                                    :end-placeholder="$t('common.applyEndTime')"
                                    clearable>
                            </el-date-picker>
                        </el-form-item>
                    </el-col>


                    <el-col :span="6">
                        <el-form-item prop="derateType" label="">
                            <el-select v-model="form.derateType" clearable :placeholder="$t('verify.plsChoose')" style="width: 100%;">
                                <el-option v-for="(item, $index) in deductionTypeList" :key="$index" :value="item.value" :label="item.label"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- 伪名 -->
                    <el-col :span="6">
                        <el-form-item prop="whiteProductName" v-if="domain == 'Bene'"> <!---->
                            <el-input v-model="form.whiteProductName" :placeholder="$t('common.productName')" clearable><!----></el-input>
                        </el-form-item>
                        <el-form-item prop="kana" v-else> <!--姓名-->
                            <select-kana-list v-model="form.kana" :multiple="false" :placeholder="$t('finance.pseudonym')"></select-kana-list><!--app名称-->
                        </el-form-item>
                    </el-col>

                </el-row>
                <el-row>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button @click="search" icon="el-icon-search" type="primary">{{ $t('common.search') }}</el-button>
                            <el-button @click="exportExcel" icon="el-icon-upload2" type="primary">{{ $t('common.export') }}</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div><!--content_panel_top-->
        <div class="module_content">
            <div class="content_panel project_modules">
                <div class="table_list">
                    <el-table :data="tableData" style="width: 100%;" :highlight-current-row="true"
                              :max-height="tableMaxHeight" :row-key="handleRowKey" tooltip-effect="light">
                        <el-table-column :label="$t('common.remitApplyId')" prop="derateId" width="200"></el-table-column><!--减免申请编号-->
                        <el-table-column :label="$t('common.innerOrderId')" prop="orderId" width="200"></el-table-column><!--内部订单号-->
                        <el-table-column :label="$t('system.appName')" prop="appName" min-width="130"></el-table-column><!--APP名称-->
                        <el-table-column v-if="domain=='Bene'" :label="$t('finance.productName')" prop="whiteProductName" min-width="130"></el-table-column><!--伪名-->
                        <el-table-column v-else :label="$t('finance.pseudonym')" prop="kana" min-width="130"></el-table-column><!--伪名-->

                        <el-table-column label="UserId" prop="userId" width="150"></el-table-column>
                        <el-table-column :label="$t('common.name')"  prop="userName" min-width="150"></el-table-column><!--姓名-->
                        <el-table-column :label="$t('common.mobileNumber')" prop="userPhone" width="150"></el-table-column><!--手机号码-->
                        <el-table-column :label="$t('common.applyDate')" prop="derateApplyTime" width="170">
                            <template slot-scope="{ row }">{{ row.derateApplyTime | formatDate('yyyy-MM-dd hh:mm:ss')}}</template><!--申请时间-->
                        </el-table-column>
                        <el-table-column prop="totalPeriods" v-if="showSpread" :label="$t('install.totalBorrowPeriod')" min-width="150"></el-table-column><!--借款总周期-->
                        <el-table-column prop="currentPeriod" v-if="showSpread" :label="$t('install.currentBorrowPeriod')" min-width="150"></el-table-column><!--借款当前周期-->

                        <el-table-column :label="$t('common.remitAmount')" prop="derateAmount" width="200"></el-table-column><!--减免金额-->
                        <el-table-column :label="$t('common.overduePeriod')" prop="teamName" width="100"></el-table-column><!--逾期阶段-->
                        <el-table-column :label="$t('common.remitType')" prop="derateType" width="150">
                            <template slot-scope="{ row }">{{ row.derateType | deductionType }}</template><!--减免类型-->
                        </el-table-column>
                        <el-table-column :label="$t('common.applyPerson')" prop="collectionUserName" width="150"></el-table-column><!--申请人-->
                        <el-table-column :label="$t('common.applyReason')" prop="reason" :show-overflow-tooltip="true" width="150"></el-table-column><!--申请理由-->
                        <el-table-column :label="$t('common.validityPeriod')" prop="validiteTime" width="170">
                            <template slot-scope="{ row }">{{ row.validiteTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template><!--有效期-->
                        </el-table-column>
                        <el-table-column :label="$t('common.colReviewTime')" prop="collectionAuditTime" width="170">
                            <template slot-scope="{ row }">{{ row.collectionAuditTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template><!--催收审核时间-->
                        </el-table-column>
                        <el-table-column :label="$t('common.colReviewPerson')" prop="collectionAuditor" width="150"></el-table-column><!--催收审核人-->
                        <el-table-column :label="$t('common.finReviewTime')" prop="financialAuditTime" width="170">
                            <template slot-scope="{ row }">{{ row.financialAuditTime | formatDate('yyyy-MM-dd hh:mm:ss')}}</template><!--财务审核时间-->
                        </el-table-column>
                        <el-table-column :label="$t('common.finReviewPerson')" prop="financialAuditor" width="150">
                            <template slot-scope="{ row }">{{ row.financialAuditor }}</template><!--财务审核人-->
                        </el-table-column>
                        <el-table-column :label="$t('common.reviewResult')"  prop="derateResult" width="150">
                            <template slot-scope="{ row }">{{ row.derateResult | derateResultType }}</template><!--审核结果-->
                        </el-table-column>
                        <el-table-column :label="$t('common.colRemark')" prop="collectionRemark" width="120" :show-overflow-tooltip="true"></el-table-column><!--催收备注-->
                        <el-table-column :label="$t('common.finRemark')" prop="financialRemark" width="120" :show-overflow-tooltip="true"></el-table-column><!--财务备注-->
                    </el-table>
                    <!--分页组件-->
                    <pagination @pageChange="pageChange" :page="page"></pagination>
                </div><!--module_content-->
            </div>
        </div><!--module_content-->
    </div>


</template>

<script>
    import Pagination from "@/components/pagination";
    import mixin from "@/service/mixin";
    import SelectAppList from '@/components/select-app-list';
    import {domain} from '@/config/'
    import SelectKanaList from '@/components/select-kana-list';

    let that = null;
    export default {
        name: "reduceAuditReduce",
        components: {
            Pagination,
            SelectAppList,
            SelectKanaList
        },
        mixins: [mixin],
        data() {
            return {
                domain:'',
                showSpread:false,
                form: {
                    orderId: "",
                    derateApplyTime: "",
                    userPhone: "",
                    withdrawAccount: "",
                    derateId: "",
                    userId: "",
                    product: "",
                    derateType: "",
                    appName: '',
                    kana:'',
                    whiteProductName:'',
                },
                rules: {
                    orderId: [],
                    derateApplyTime: [],
                    userPhone: [],
                    withdrawAccount: [],
                    derateId: [],
                    userId: [],
                    product: [],
                    derateType: []
                },
                deductionTypeList: [
                    { value: '', label: this.$t('common.all') },// 全部
                    { value: '0', label: this.$t('common.validityRemit') },// 有效期减免
                    { value: '1', label: this.$t('common.foreverRemit') },// 永久性减免
                ],
            };
        },
        methods: {
            getTableData(page = this.page) {
                let params = this.fillParams(page);
                this.$api.finance.remit.queryDerateInfo(params).then(res => {
                    let {status, data, error} = res;
                    if ("1" === status && "00000000" === error && data) {
                        this.tableData = data.resultData;
                        this.setPage(data.page, this.page);
                    }
                });
            },
            search() {
                this.page.currentPage = 1;
                this.getTableData();
            },
            exportExcel() {
                let params = this.fillParams();
                const user = this.$storage.get("user");
                const language = this.$storage.getLocal('language');
                params.language = language;
                params.token = user.token;
                const {$apiConf} = this;
                const url = this.$urlUtil.fillParams(params, $apiConf.baseUrl + $apiConf.urlType.finance.remit.exportDerateInfo, ["page"]);
                this.$openNewBlank(url);
            },
            fillParams(page = this.page) {
                const form = this.form;
                const params = {
                    orderId: "",
                    derateApplyTimeStart: "",
                    derateApplyTimeEnd: "",
                    userPhone: "",
                    withdrawAccount: "",
                    derateId: "",
                    userId: "",
                    product: "",
                    derateType: "",
                    appName: '',
                    kana:'',
                    whiteProductName:'',
                    page: {
                        pageNo: page.currentPage,
                        pageSize: this.page.pageSize
                    }
                };
                Object.keys(form).forEach(key => {
                    if (typeof form[key] === "string" && form[key]) {
                        form[key] = form[key].trim();
                        params[key] = form[key];
                    }
                });
                if (form.derateApplyTime) {
                    params.derateApplyTimeStart = form.derateApplyTime[0];
                    params.derateApplyTimeEnd = form.derateApplyTime[1];
                }
                return params;
            },
            // 列表多选处理
            handleTableSelect(val) {
                this.selectedIdList.ids = [];
                this.selectedIdList.orderIds = [];
                val.forEach(item => {
                    this.selectedIdList.ids.push(item.id);
                    this.selectedIdList.orderIds.push(item.orderId);
                });
            },
            // 处理行数据
            handleRowKey(row) {
                return row.id;
            }
        },
        filters: {
            deductionType(deductionType){
                switch (deductionType) {
                    case 0:
                        return that.$t('common.validityRemit');// 有效期减免
                    case 1:
                        return that.$t('common.foreverRemit');// 永久性减免
                    default:
                        return '-';
                }
            },
            derateResultType(derateResultType){
                switch (derateResultType) {
                    case 0:
                        return that.$t('common.finReviewing');// 财务审核中
                    case 1:
                        return that.$t('common.finReviewRefuse');// 财务审核拒绝
                    case 2:
                        return that.$t('common.finReviewSuccess');// 财务审核通过
                    default:
                        return derateResultType;
                }
            }
        },
        created() {
            this.domain = this.$storage.get('user').domain
            this.showSpread = domain.showSpread();
            that = this;
            this.tableMaxHeight = document.body.clientHeight - 280;
            this.getTableData();
        }
    };
</script>

<style lang="scss" scoped>
</style>
